<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------

namespace app\common\model;

/**
* 用户模型
*/
class Liwu extends Base{
    /*礼物列表*/
    public function liebiao($id){
        $order = "id desc";
        $this_id = $_SESSION['index']['user_auth']['uid'];
        if(1 == $id){
            /*收到的礼物*/
            $result = $this->db()->where(array('jieshou'=>$this_id))->order($order)->select();
            foreach($result as $key => $value){
                $list  = model('Member')->where(array('uid'=>$value['fasong']))->find();
                $value['username'] = $list['username'];
                $value['touxiang'] = $list['touxiang'];
            }
            return $result;
        }else{
            /*发送的礼物*/
            $result = $this->db()->where(array('fasong'=>$this_id))->order($order)->select();
            foreach($result as $key => $value){
                $list  = model('Member')->where(array('uid'=>$value['jieshou']))->find();
                $value['username'] = $list['username'];
                $value['touxiang'] = $list['touxiang'];
                $value['liwu'] = json_decode($value['liwu']);
            }
            return $result;
        }
    }
    /*删除礼物*/
    public function quchu($id){
        return $this->db()->where(array('Id'=>$id))->delete();
    }

}